﻿using Commonality.Model;
using Merge.BLL;
using Merge.BLL.CaverForm;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WZS_Auto_Classifying_Merge
{
    public partial class MainForm : Form
    {
        private LogForm logForm;
        private ConfigForm configForm;
        private ClassifyControlForm classifyControlForm;

        public MainForm()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            logForm = new LogForm();
            configForm = new ConfigForm();
            classifyControlForm = new ClassifyControlForm();

            InitForm();
            MergeAutoMain.MergeStart();
            InitCaverForm();




        }
        private void InitForm()
        {
            //
            logForm.FormBorderStyle = FormBorderStyle.None;
            logForm.Size = panelLog.Size;
            logForm.BackColor = this.BackColor;
            logForm.TopLevel = false;
            logForm.Dock = DockStyle.Fill;
            panelLog.Controls.Add(logForm);
            logForm.Show();
            //
            configForm.FormBorderStyle = FormBorderStyle.None;
            configForm.Size = ConfigPanel.Size;
            configForm.BackColor = this.BackColor;
            configForm.TopLevel = false;
            configForm.Dock = DockStyle.Fill;
            ConfigPanel.Controls.Add(configForm);
            configForm.Show();
            //
            classifyControlForm.FormBorderStyle = FormBorderStyle.None;
            classifyControlForm.Size = ClassifyControlFormPanel.Size;
            classifyControlForm.BackColor = this.BackColor;
            classifyControlForm.TopLevel = false;
            classifyControlForm.Dock = DockStyle.Fill;
            ClassifyControlFormPanel.Controls.Add(classifyControlForm);
            classifyControlForm.Show();



        }
        private void InitCaverForm()
        {
            //
            MergeAutoMain.caverForm.FormBorderStyle = FormBorderStyle.None;
            MergeAutoMain.caverForm.Size = CaverPanel.Size;
            MergeAutoMain.caverForm.BackColor = this.BackColor;
            MergeAutoMain.caverForm.TopLevel = false;
            MergeAutoMain.caverForm.Dock = DockStyle.Fill;
            CaverPanel.Controls.Add(MergeAutoMain.caverForm);
            MergeAutoMain.caverForm.Show();
        }

        private void OpenConfigPage_Click(object sender, EventArgs e)
        {
            ConfigPanel.BringToFront();
            if (!configForm.Visible)
            {
                foreach (var item in ConfigPanel.Controls)
                {
                    if (item is Form)
                    {
                        ((Form)item).Visible = false;
                    }
                }
                configForm.Visible = true;
            }
            Log4Net.MsgInfo("进入Config页");
        }

        private void Debug_Click(object sender, EventArgs e)
        {
            DebugForm debugForm = new DebugForm();
            debugForm.Show();
        }

        private void OpenClassControl_Click(object sender, EventArgs e)
        {
            ClassifyControlFormPanel.BringToFront();
            if (!classifyControlForm.Visible)
            {
                foreach (var item in ClassifyControlFormPanel.Controls)
                {
                    if (item is Form)
                    {
                        ((Form)item).Visible = false;
                    }
                }
                classifyControlForm.Visible = true;
            }
            Log4Net.MsgInfo("进入类控制页");
        }

        private void OpenCaverPage_Click(object sender, EventArgs e)
        {
            MergeAutoMain.caverForm.TopLevel = false;
            CaverPanel.Controls.Add(MergeAutoMain.caverForm);
            CaverPanel.BringToFront();
            if (!MergeAutoMain.caverForm.Visible)
            {
                foreach (var item in CaverPanel.Controls)
                {
                    if (item is Form)
                    {
                        ((Form)item).Visible = false;
                    }
                }
                MergeAutoMain.caverForm.Visible = true;
            }
            Log4Net.MsgInfo("进入仓控制页");
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            MergeAutoMain.ThisClose = true;
            DialogResult result = MessageBox.Show("软件中断中\r\n你确定要关闭吗！", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if (result == DialogResult.OK)
            {
                e.Cancel = false;  //点击OK   
                MergeAutoMain.MergeStop();
            }
            else
            {
                MergeAutoMain.ThisClose = false;
                e.Cancel = true;
            }
        }
    }
}
